package com.hk.controller;

import com.hk.core.PageResult;
import com.hk.core.R;
import com.hk.service.IndexService;
import com.hk.vo.BusinessChangeLevelVo;
import com.hk.vo.ClueChangeLevelVo;
import com.hk.vo.IndexClueVo;
import com.hk.vo.TodayInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@RestController
public class IndexController {
    @Autowired
    IndexService indexService;

    //今日简报
    @GetMapping("/index/getTodayInfo")
    public R todayIndex(){
      TodayInfo vo=indexService.todayIndex();
        return R.ok(vo);
    }

    //线索转化漏斗
    @GetMapping("/report/getVulnerabilityMap/{starDate}/{endDate}")
    public R queryClue(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate starDate,
                       @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate )
    {
        LocalDateTime star = starDate.atStartOfDay();
        LocalDateTime end = endDate.plusDays(1).atStartOfDay();
       IndexClueVo vo=indexService.queryClue(star,end);
        return R.ok(vo);
    }

    //商机转化龙虎榜
    @GetMapping("/index/businessChangeStatistics")
    public R queryBusinessChangeStatic(String  beginCreateTime,
                                       String  endCreateTime)
    {
        LocalDate starDate  = LocalDate.parse(beginCreateTime);
        LocalDate endDate = LocalDate.parse(endCreateTime);

        LocalDateTime star = starDate.atStartOfDay();
        LocalDateTime end = endDate.plusDays(1).atStartOfDay();
        List<BusinessChangeLevelVo> vo= indexService.queryBusinessChangeStatic(star,end);
        return R.ok(vo);
    }

    //线索转化龙虎榜
    @GetMapping("index/salesStatistic")
    public R queryClueChangeStatic(String beginCreateTime,String endCreateTime){
        LocalDate starDate  = LocalDate.parse(beginCreateTime);
        LocalDate endDate = LocalDate.parse(endCreateTime);

        LocalDateTime star = starDate.atStartOfDay();
        LocalDateTime end = endDate.plusDays(1).atStartOfDay();
        List<ClueChangeLevelVo> vo=indexService.queryClueChangeStatic(star,end);
        return R.ok(vo);
    }

//    //未知的请求
//    @GetMapping("/index")
//    public R unKnow(){
//        return R.ok();
//    }
}
